package com.cyt.sys.util;

/**
 * Created by sunli on 2019/4/18.
 */
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

public class PostClient {

    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(PostClient.class);

    public static String postRequest(RestTemplate restTemplate,String jsonString,String url){
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        LOG.info(String.format("本次传递数据：%s", jsonString));
        HttpEntity<String> formEntity = new HttpEntity<String>(jsonString, headers);
        String result = restTemplate.postForObject(url,formEntity,String.class);
        if(result.equals("success")){
            LOG.info(String.format("本次操作：%s", result));
        }else{
            LOG.info(String.format("本次操作：%s", result));
        }
        return result;
    }
}
